package net.monare.mifss.admin.ui.comp;

import net.monare.mifss.MifssMessages;
import net.monare.mifss.admin.ui.win.ConfigureStorageWindow;
import net.monare.mifss.configurations.pojo.StorageDef;
import net.monare.mifss.evn.ConfigureSelectedStorageListener;

import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.NativeButton;
import net.monare.mifss.evn.ReCreateSelectedStorageListener;

public class StorageDefUiLink extends HorizontalLayout {

	private static final long serialVersionUID = 1439845976217702496L;

	public static final String NAME_WIDTH = "80px";
	public static final String TITLE_WIDTH = "80px";
	public static final String BUTTON_WIDTH = "70px";

	private Label storageNameLabel;
	private Label storageTitleLabel;
	private NativeButton configureStorage;
    private NativeButton reCreateStorage;

	public StorageDefUiLink(StorageDef storageDef, ConfigureStorageWindow parent, boolean active) {

		storageNameLabel = new Label(storageDef.getName());
		storageNameLabel.setWidth(NAME_WIDTH);

		storageTitleLabel = new Label(storageDef.getTitle());
		storageTitleLabel.setWidth(TITLE_WIDTH);

		configureStorage = new NativeButton(MifssMessages.getMessage("button.configure"));
		configureStorage.setWidth(BUTTON_WIDTH);
        configureStorage.addClickListener(new ConfigureSelectedStorageListener(parent, storageDef));
        configureStorage.setEnabled(active);

        addComponent(storageNameLabel);
        addComponent(storageTitleLabel);
        addComponent(configureStorage);

        if(storageDef.isChained()){
            reCreateStorage = new NativeButton(MifssMessages.getMessage("button.re.create"));
            reCreateStorage.addClickListener(new ReCreateSelectedStorageListener(storageDef));
            reCreateStorage.setEnabled(active);
            addComponent(reCreateStorage);
        }

	}

}
